home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
By the Book
/
Mac C Primer V1 CW9
/
68K and PPC Projects (CW9)
/
4.3 - EventTrigger
/
EventTrigger.c
< prev
Wrap
C/C++ Source or Header
|
1996-05-28
|
2KB
|
109 lines
/********************************************************/
/* */
/* EventTrigger Code from Chapter Four of */
/* */
/* ** The Macintosh C Programming Primer, 2nd Ed. ** */
/* */
/* Copyright 1992, Dave Mark and Cartwright Reed */
/* */
/* This program demonstrates specific Mac programming */
/* techniques. */
/* */
/********************************************************/
/* Note that the isHighLevelEventAware flag is set in the
Project preferences panel (in the SIZE popup) in
BOTH EventTracker and in EventTrigger. If you don't do this,
EventTrigger won't be able to send the Apple events
and EventTracker won't be able to receive them!!!
Also, be sure the Application Creator is set to
'Prmr' in EventTracker so EventTrigger can
find it. - Dave
*/
#include <AppleEvents.h>
#include <GestaltEqu.h>
#define kGestaltMask 1L
/***************/
/* Functions */
/***************/
void ToolBoxInit( void );
void EventsInit( void );
void SendEvent( AEEventID theAEEventID );
/******************************** main *********/
void main( void )
{
ToolBoxInit();
EventsInit();
SendEvent( kAEOpenApplication );
SendEvent( kAEOpenDocuments );
SendEvent( kAEPrintDocuments );
SendEvent( kAEQuitApplication );
}
/*********************************** ToolBoxInit */
void ToolBoxInit( void )
{
InitGraf( &qd.thePort );
InitFonts();
InitWindows();
InitMenus();
TEInit();
InitDialogs( 0L );
InitCursor();
}
/*********************************** EventsInit */
void EventsInit( void )
{
long feature;
OSErr err;
err = Gestalt( gestaltAppleEventsAttr, &feature );
if ( err != noErr )
{
SysBeep( 10 ); /* Error calling Gestalt!!! */
ExitToShell();
}
if ( !( feature & ( kGestaltMask << gestaltAppleEventsPresent ) ) )
{
SysBeep( 10 ); /* AppleEvents not supported!!! */
ExitToShell();
}
}
/******************************** SendEvent *********/
void SendEvent( AEEventID theAEEventID )
{
OSErr err;
AEAddressDesc address;
OSType appSig;
AppleEvent appleEvent, reply;
appSig = 'Prmr';
err = AECreateDesc( typeApplSignature, (Ptr)(&appSig),
(Size)sizeof( appSig ), &address );
err = AECreateAppleEvent( kCoreEventClass, theAEEventID, &address,
kAutoGenerateReturnID, 1L, &appleEvent );
err = AESend( &appleEvent, &reply, kAENoReply + kAECanInteract,
kAENormalPriority, kAEDefaultTimeout, nil, nil );
}